package es.xpt.ysf.commons.issues;

import java.io.InputStream;
import java.util.List;

import javax.ejb.Local;

import es.xpt.ysf.YSFException;
import es.xpt.ysf.commons.issues.model.Issue;
import es.xpt.ysf.commons.issues.model.IssueHistory;
import es.xpt.ysf.commons.issues.model.IssueSubscribers;
import es.xpt.ysf.commons.issues.model.IssueValue;
import es.xpt.ysf.commons.issues.model.Issue.IssuePriority;

@Local
public interface IssueSession {

	/**
	 * 
	 * Adds an issue to the system if it does not exist in the system as an opened issue.
	 * 
	 * @param issue
	 * @param entity
	 * @param entityId
	 * @param businessArea
	 * @param parameters
	 * @throws YSFException
	 * @return true if the issue has been added to the system. 
	 */
	
	public boolean addIssueNewTransaction(Issue issue, String entity, String entityId,
			String businessArea, IssuePriority priority, Object[] parameters, InputStream jcrData) throws YSFException;
	
	public boolean addIssue ( Issue issue, String entity, String entityId, String businessArea, IssuePriority priority, Object[] parameters, InputStream jcrData, String jcrDataMimeType ) throws YSFException;
	
	/**
	 * Gets an existing issue.
	 * 
	 * @param id
	 * @return
	 * @throws YSFException
	 */
	public IssueValue getIssue ( String id ) throws YSFException;
	
	
	/**
	 * @param issueValue
	 * @throws YSFException
	 */
	public void updateIssue ( IssueValue issueValue ) throws YSFException;
	
	
	/**
	 * @param issueId
	 * @param history
	 * @throws YSFException
	 */
	public void addHistoryItem ( String issueId, IssueHistory history ) throws YSFException;
	
	
	
	/**
	 * Gets the subscribers of a given entity in a business area. If the entity is <code>null</code>, returns
	 * all the subscribers for a given business area. 
	 * 
	 * @param businessArea
	 * @param relatedUsersEntity
	 * @return
	 * @throws YSFException
	 */
	public IssueSubscribers getSubscribers ( String businessArea , String relatedUsersEntity ) throws YSFException;
	
	/**
	 * Updates the subscribers of an existing business area. 
	 * 
	 * @param businessArea
	 * @param subscribers
	 * @throws YSFException
	 */
	public void setSubscribers ( String businessArea, IssueSubscribers subscribers ) throws YSFException;
	
	/**
	 * @param issueValue
	 * @return
	 * @throws YSFException
	 */
	public List<IssueValue> searchIssue ( IssueSearchParams searchParameters ) throws YSFException;
	
	/**
	 * Gets the different business areas with at least one issue in the system. 
	 * 
	 * @throws YSFException
	 */
	public List<String> getBusinessAreas() throws YSFException;
	
	/**
	 * Gets the different roles subscribed to at least one business area in the system. 
	 * 
	 * @throws YSFException
	 */
	public List<String> getSubscribedRoles() throws YSFException;
	
	/**
	 * Gets the different users subscribed to at least one business area in the system. 
	 * 
	 * @throws YSFException
	 */
	public List<String> getSubscribedUsers() throws YSFException;
}
